export default {
  data() {
    return {
      isShow: false,
      loadStatus: '',
      params: {
        year: true,
        month: true,
        day: false,
        hour: false,
        minute: false,
        second: false
      },
      show: false,
      list: [],
      year: '',
      month: '',
      endYear: '', //结束年限
      defaultTime: '',
      isType: false,
      isChoose: 0,
      status: [{
        status: 0,
        text: '全部状态'
      }, {
        status: 1,
        text: '待审核'
      }, {
        status: 2,
        text: '已成功'
      }, {
        status: 3,
        text: '已失败'
      }],
      text: '全部状态',
      state: 0,
      pageIndex: 1,
      chooseId: 0,
      chooseText: '全部状态'
    }
  },
  created() {
    //获取当前年月
    let date = new Date()
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    month = month > 9 ? month : '0' + month
    this.year = year
    this.endYear = year
    this.month = month
    this.defaultTime = `${year}-${month}`
    this.withdrawRecords()
  },
  filters: {
    million(value) { //过万处理
      let num
      num = value.toFixed(2)
      return num
    },
    cutString(str, len) {
      if (str.length * 2 <= len) {
        return str
      }
      let strlen = 0
      let s = ''
      for (let i = 0; i < str.length; i++) {
        s = s + str.charAt(i)
        if (str.charCodeAt(i) > 128) {
          strlen = strlen + 2
          if (strlen >= len) {
            return s.substring(0, s.length - 1) + '...'
          }
        } else {
          strlen = strlen + 1
          if (strlen >= len) {
            return s.substring(0, s.length - 2) + '...'
          }
        }
      }
      return s
    },
    formatStoreType(data) {
      let text = ''
      switch (Number(data)) {
      case 100:
        text = '待审核'
        break
      case 200:
        text = '已成功'
        break
      case 240:
        text = '待审核'
        break
      case 260:
        text = '已失败'
        break
      default:
        text = '已失败'
        break
      }
      return text
    }
  },
  methods: {
    //状态选中确定
    comfig() {
      this.isType = false
      this.state = this.chooseId
      this.text = this.chooseText
      this.list = []
      this.pageIndex = 1
      this.withdrawRecords()
    },
    // 加载前、中、后
    moreStatus(status) {
      this.loadStatus = status
    },
    more() {
      this.withdrawRecords()
    },
    async withdrawRecords() {
      let userId = uni.getStorageSync('Ztc_C_USER_INFO').id
      try {
        let data = {
          'accountId': userId,
          'pageIndex': this.pageIndex,
          'pageSize': 5,
          'status': this.state,
          'Month': this.defaultTime
        }
        const res = await this.$api.fundModule.withdrawRecords(data)
        if (res.data.list === null) {
          res.data.list = []
        }
        if (res.data.list.length === 0) {
          this.isShow = true
        }
        this.list = [...this.list, ...res.data.list]
        if (res.data.total <= 10) {
          this.loadStatus = 'nomore'
        } else {
          this.moreStatus(res.data.list.length !== 0 ? 'loadmore' : 'nomore')
        }
        uni.hideLoading()
        if (res.data.list.length === 0) return false
        this.pageIndex += 1 // 当前页加1

      } catch (e) {
        //TODO handle the exception
      }
    },
    select(id, text) {
      this.chooseId = id
      this.chooseText = text
      this.pageIndex = 1
      this.isChoose = id
      // this.text = text
    },
    //日期选中确定
    confirm(e) {
      this.year = e.year
      this.month = e.month
      this.defaultTime = `${e.year}-${e.month}`
      this.list = []
      this.pageIndex = 1
      this.withdrawRecords()
    },
  }
}
